﻿<Window x:Class="AGMLite.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:my="clr-namespace:AGMLite.UserControl" 
        xmlns:vm="clr-namespace:AGMLite.ViewModelClass"        
        xmlns:local="clr-namespace:AGMLite"
        xmlns:tb="http://www.hardcodet.net/taskbar"
        Title="HP Agile Management Lite" Height="600" Width="350" MaxWidth="500" MaxHeight="800" MinHeight="150" MinWidth="300" Icon="/AGMLite;component/images/agm.ico" Closed="Window_Closed" WindowStartupLocation="CenterScreen" ResizeMode="CanResizeWithGrip" Closing="Window_Closing">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <local:ProjectIconConverter x:Key="ProjectIconConverter" />
                    <local:ProjectStatusConverter x:Key="ProjectStatusConverter" />
                    <Style TargetType="{x:Type Image}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type UIElement}, AncestorLevel=1}, Path=IsEnabled}"  Value="False">
                                <Setter Property="Opacity"  Value="0.5" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>        
    </Window.Resources>
    <Grid>
        <tb:TaskbarIcon  x:Name="AGMLiteNotifyIcon"  IconSource="/AGMLite;component/images/agm.ico"  ToolTipText="HP Agile Management Lite" TrayMouseDoubleClick="AGMLiteNotifyIcon_TrayMouseDoubleClick">
            <tb:TaskbarIcon.TrayToolTip>
                <Border  Background="White"  BorderBrush="Orange" BorderThickness="2"  CornerRadius="4" Opacity="0.8"  Width="160"  Height="40">
                    <TextBlock Text="HP Agile Management Lite" HorizontalAlignment="Center" VerticalAlignment="Center" />
                </Border>
            </tb:TaskbarIcon.TrayToolTip>
            <tb:TaskbarIcon.ContextMenu>
                <ContextMenu>
                    <MenuItem Name="miShow" Header="Show AGMLite Window" Click="miShow_Click" />
                    <Separator />
                    <MenuItem Name="miExit" Header="Exit" Click="miExit_Click" />
                </ContextMenu>
            </tb:TaskbarIcon.ContextMenu>
        </tb:TaskbarIcon>
        <TabControl HorizontalAlignment="Stretch" Name="mainTab" VerticalAlignment="Stretch" Margin="1"  ItemsSource="{Binding ProjectCollection}" Loaded="mainTab_Loaded">
            <TabControl.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Add" Command="{Binding AddCommand}">
                        <MenuItem.Icon>
                            <Image Source="/AGMLite;component/images/add.png"  Height="20" Width="20"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Edit" Command="{Binding EditCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.SelectedItem}">
                        <MenuItem.Icon>
                            <Image Source="/AGMLite;component/images/edit.png"  Height="20" Width="20"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Connect" Command="{Binding ConnectCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.SelectedItem}">
                        <MenuItem.Icon>
                            <Image Source="/AGMLite;component/images/connect.png"  Height="20" Width="20"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Delete" Command="{Binding DeleteCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.SelectedItem}">
                        <MenuItem.Icon>
                            <Image Source="/AGMLite;component/images/delete.png" Height="20" Width="20" />
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
            </TabControl.ContextMenu>
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Image Name="imgProjectStatus" VerticalAlignment="Top" 
                               Source="{Binding Path=Project.Status, Converter={StaticResource ProjectStatusConverter}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" 
                               ToolTip="{Binding Path=Project.Message}" />
                        <Image Name="imgProject" Height="32" Width="32" 
                               Source="{Binding Path=Project.Icon, Converter={StaticResource ProjectIconConverter}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" 
                               ToolTip="{Binding Path=Project.Name}" />
                    </StackPanel>                    
                </DataTemplate>                
            </TabControl.ItemTemplate>
            <TabControl.ContentTemplate>
                <DataTemplate>
                    <Grid Width="{Binding ElementName=mainTab, Path=ActualWidth}" Height="{Binding ElementName=mainTab, Path=ActualHeight}">
                        <my:ItemsUserControl Margin="2,2,10,20" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
                    </Grid>
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>
    </Grid>
</Window>
